Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jan 13, 2026

Which issue does this PR close?

Rationale for this change

I am trying to encourage people to avoid using ArrayData when constructing arrays (as it is slower than just creating the arrays directly). Part of doing so is ensuring that the APIs to create the necessary pieces (NullBuffers in particular) are easy to use / well documented.

As pointed out by @scovich on #9120 (comment), it is

  1. Not obvious how finish works (resets the builder)
  2. Why there is no build method (when there is a From impl)

Thus, let's add build methods to NullBufferBuilder and document the difference between finish and build

While I was working on this change, I noticed the same issue with BufferBuilder and BooleanBufferBuilder so I also made them consistent

What changes are included in this PR?

  1. Improve docs and Add build() method to {Null,Boolean,}BufferBuilder

Are these changes tested?

Yes by CI and new doc examples

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 13, 2026
///
/// `NullBuffer`s can be creating using [`NullBufferBuilder`]
/// # See also
/// * [`NullBufferBuilder`] for creating `NullBuffer`s
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding some comments here to help navigate the maze of builders available

///
/// This consumes the builder. Use [`Self::finish`] to reuse it.
#[inline]
pub fn build(self) -> BooleanBuffer {
Copy link
Contributor Author

@alamb alamb Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most builders have a build method. The fact that the *Buffer builders in the crate do not is a small source of API friction I would like to remove

/// This builder only materializes the buffer when we append `false`.
/// If you only append `true`s to the builder, what you get will be
/// `None` when calling [`finish`](#method.finish).
/// This builder only materializes the buffer when null values (`false`) are
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by wording cleanup

///
/// # See Also
///
/// * [`NullBuffer`] for building [`BooleanBuffer`]s for representing nulls
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NullBufferBuilder is the correct reference so I fixed that

@alamb alamb force-pushed the alamb/add_build_to_builders branch from 7fa4c47 to b2e5fe4 Compare January 13, 2026 14:32
@alamb alamb added the documentation Improvements or additions to documentation label Jan 13, 2026
@alamb alamb marked this pull request as ready for review January 13, 2026 14:33
@alamb alamb changed the title Improve docs and Add build() method to {Null,Boolean,}BufferBuilder Improve docs and add build() method to {Null,Boolean,}BufferBuilder Jan 13, 2026
@alamb alamb changed the title Improve docs and add build() method to {Null,Boolean,}BufferBuilder Improve docs and add build() method to {Null,Boolean,}BufferBuilder Jan 13, 2026
Copy link
Contributor

@scovich scovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 212 to 213
self.bitmap_builder
.map(|mut builder| NullBuffer::new(builder.finish()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside: Is there an impl From that would allow this?

Suggested change
self.bitmap_builder
.map(|mut builder| NullBuffer::new(builder.finish()))
self.bitmap_builder.map(Into::into)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call -- done in b844e5a

Copy link
Contributor

@etseidl etseidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alamb, just a few nits.

@alamb alamb merged commit ac81eb2 into apache:main Jan 14, 2026
25 of 26 checks passed
@alamb
Copy link
Contributor Author

alamb commented Jan 14, 2026

Thanks again everyone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants